package org.ntu.rtsearch.search.model;

import java.util.Comparator;

public class ScoreDoc {
	public int docId;
	
	public double score;
	
	private static Comparator<ScoreDoc> comp;
	
	public ScoreDoc(int docId, float score) {
		this.docId = docId;
		this.score = score;
	}
	
	public ScoreDoc(Scorer scorer) {
		this.docId = scorer.docId;
		this.score = scorer.rankScore();
	}
	
	
	/**
	 * get single instance of Comparator
	 * @return
	 */
	public static synchronized Comparator<ScoreDoc> getComp() {
		if(comp == null) {
			comp = new Comparator<ScoreDoc>() {
				public int compare(ScoreDoc o1, ScoreDoc o2) {
					return o1.score > o2.score ? 1 : (o1.score < o2.score ? -1 : 0);
				}
			};
		}
		return comp;
	}
	
}
